#ifndef _COMM_H
#define _COMM_H

#include "sc95f.h"

#define USER_CMD_INDEX_NONE       0x00
#define USER_CMD_INDEX_SET        0x01
#define USER_CMD_INDEX_GET_F0     0x02
#define USER_CMD_INDEX_GET_F1     0x03
#define USER_CMD_INDEX_GET_F2     0x04
#define USER_CMD_INDEX_INF        0x05

#define COMM_PACKAGE_SIZE         (6)
#define PACK_CMD_OFFSET           (3)   /* 通信包中命令的偏移 */
#define PACK_DATA_OFFSET          (4)   /* 通信包中数据的偏移 */

/* transmit command */
#define TEXT_SET        0x53
#define TEXT_GET        0x47
#define TEXT_RES        0x52
#define TEXT_INF        0x49
#define TEXT_ACK        0x41
#define TEXT_NAK        0x4E


#define CMD_SOFTWEAR_VER        0x10  //softwear version
#define CMD_WIFI_PROTOCOL       0x11  //
#define CMD_REAL_TIME           0x12
#define CMD_MACHINE_DATA        0xF0
#define CMD_RUN_STATE           0xF1
#define CMD_SERVICE_DATA        0xF2
#define CMD_KEY_SETTING         0xF4


//#define SET_KEY_CHILDLOCK       0x00
#define SET_KEY_POWER           0x01//0x00
#define SET_KEY_NORMALMODE      0x02
#define SET_KEY_WATERSHOCK      0x03
#define SET_KEY_PREUSSMODE        0x04
#define SET_F4_CYCLE_ENA        0x04
#define SET_F4_CYCLE_MODE       0x05
#define SET_F4_SUPER_ENA        0x06
#define SET_KEY_ECO             0x0A
#define SET_KEY_TEMPUP          0x19
#define SET_KEY_TEMPDOWN        0x1A
#define SET_KEY_TEMPSET         0x1B
#define SET_KEY_NONE            0XFF

#define COMM_TIMEOUT            12//59//250
#define COMM_TIMEOUT_INIT       15//77

#define STXdata 0
#define SORTdata 1
#define LENGTHdata 2
#define COMMANDdata 3
#define TEXTdata 4
#define ETXdata 5
#define BCCdata 6

#define stx_date 0x02
#define sort_date 0x09
#define etx_date 0x03



typedef union
{
    uint8_t  buf[70];
    struct
    {
		uint8_t head; 
		uint8_t lenth;
		uint8_t msg_type;
		uint8_t msg_id;
		uint8_t cmd_type;
		uint8_t cmd_id;
		uint8_t mcu_data[64];     
    }pkt;
}SEND_FRAME_u;

typedef union
{
    uint8_t  buf[70];
    struct
    {
		uint8_t head; 
		uint8_t lenth;
		uint8_t msg_type;
		uint8_t msg_id;
		uint8_t cmd_type;
		uint8_t cmd_id;
		uint8_t mcu_data[64];     
    }pkt;
}GET_FRAME_u;

extern GET_FRAME_u get_data;
extern SEND_FRAME_u send_data;

typedef enum 
{    
    SEND1_END=0,
    SEND1_RUN
}SEND1_FLAG;

typedef struct 
{
    SEND1_FLAG send_flag;
    uint8_t *pdata1;
    uint8_t pdata_len;
    uint8_t send_len;
}UART1_SEND;
extern UART1_SEND uart1_send_flag;
 void comm_process(void);

void comm_rinnai_init(void);
uint8_t UART1_IT_SEND_START_function(UART1_SEND *uart_send,uint8_t *bpata,uint8_t bpata_len);
uint8_t UART1_IT_SEND_FUNCTION(UART1_SEND *uart_send);
 uint8_t UART_MB_Get_Date(uint8_t date);

/**  @brief send F4 Command to mainboard
 */
void MB_SetCommand(uint8_t cmd);

#if 1 /* Passthrough to wifi */
 

enum{
   PASS_F0 = 0,
   PASS_F2,
   PASS_NUM,
};

uint8_t WifiForwarding(void);
void uart_resp_key_message(void);
#endif

#endif